
package com.android.test.model;

import com.android.test.R;
import com.android.test.util.GlobalUtil;

import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.preference.DialogPreference;
import android.util.AttributeSet;

public class DialogExPreference extends DialogPreference {
    private Context context;

    public DialogExPreference(Context oContext, AttributeSet attrs) {
        super(oContext, attrs);
        context = oContext;
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        super.onClick(dialog, which);
        if (which == -1) {
            try {
                new ClearTask().execute("");
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

    private class ClearTask extends AsyncTask<String, Integer, Boolean> {
        @Override
        protected Boolean doInBackground(String... params) {
/*            DownloadManager.getInstance(context).trimDatabase();
            FileManager.deleteAllFiles(context, false);*/
            return true;
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {
                GlobalUtil.shortToast(context, R.string.data_clean_finish);
            }
        }
    }
}
